let vm = new Vue({
    el: "#app",
    data: {
        listArr: [{ pic: "img/01.png", name: "秋刀鱼/斤", price: 35, num: 1 },
        { pic: "img/02.png", name: "鲜大带鱼/条", price: 45, num: 1 },
        { pic: "img/03.png", name: "鲜活全母皮皮虾/斤", price: 85, num: 1 },
        { pic: "img/04.png", name: "13-15头鲍鱼/只", price: 35, num: 1 }]
    },
    methods: {
        reduce(item) {
            if (item.num > 1) {
                item.num--;
            }
        },
        add(item) {
            if (item.num < 6) {
                item.num++;
            }
        },
        clear() {
            this.listArr = [];
        }
    },
    computed: {
        totalPrice() {
            let sum = 0;
            this.listArr.forEach(element => {
                sum += element.price * element.num
            });
            return sum;
        },
        totalNum() {
            let sum = 0;
            this.listArr.forEach(element => {
                sum += element.num;
            });
            return sum;
        }
    }
})